package com.dianrui.agent.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dianrui.agent.R;
import com.dianrui.agent.bean.FinaceDetailBean;
import com.dianrui.agent.bean.Rank;

import java.util.List;

public class FinaceDetailItemAdapters extends BaseQuickAdapter<FinaceDetailBean,BaseViewHolder> {


    private Context mContext;
    private List<FinaceDetailBean>data;

    public FinaceDetailItemAdapters(Context context,List<FinaceDetailBean>list) {
        super(R.layout.item_finace_detail);
        mContext=context;
        this.data = list;
    }
    @Override
    protected void convert(final BaseViewHolder helper, FinaceDetailBean bean) {
        helper.setText(R.id.title,bean.title);
        helper.setText(R.id.discounts,bean.value);
        if(helper.getLayoutPosition()==0){
            helper.setBackgroundRes(R.id.layout1,R.drawable.blue_half_shape2);
            helper.setTextColor(R.id.title, mContext.getResources().getColor(R.color.white));
            helper.setTextColor(R.id.discounts, mContext.getResources().getColor(R.color.white));
        }else  if(helper.getLayoutPosition()== data.size() - 1){
            helper.setBackgroundRes(R.id.layout1,R.drawable.white_shape2);
            helper.setTextColor(R.id.title,mContext.getResources().getColor(R.color.black));
            helper.setTextColor(R.id.discounts, mContext.getResources().getColor(R.color.black));
        }else {
            helper.setBackgroundRes(R.id.layout1,R.color.white);
            helper.setTextColor(R.id.title,mContext.getResources().getColor(R.color.black));
            helper.setTextColor(R.id.discounts, mContext.getResources().getColor(R.color.black));
        }


        final RecyclerView subRecyView = helper.itemView.findViewById(R.id.subRecyView);
        final ImageView expand_img = helper.itemView.findViewById(R.id.expand_img);
        final ImageView expand_img1 = helper.itemView.findViewById(R.id.expand_img1);
        expand_img1.setVisibility(View.GONE);
        subRecyView.setVisibility(View.GONE);
        if(!bean.subclass.isEmpty()){
            expand_img.setVisibility(View.VISIBLE);

            FinaceSubItemAdapters subItemAdapters=new FinaceSubItemAdapters();
            subRecyView.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
            subRecyView.setAdapter(subItemAdapters);
            subRecyView.setNestedScrollingEnabled(false);
            subItemAdapters.setNewData(bean.subclass);
        }else {
            expand_img.setVisibility(View.GONE);
        }

        //展开
        helper.setOnClickListener(R.id.layout1, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (helper.getLayoutPosition()==1) {
                    if (subRecyView.getVisibility()==View.GONE) {
                        subRecyView.setVisibility(View.VISIBLE);
                        expand_img.setVisibility(View.GONE);
                        expand_img1.setVisibility(View.VISIBLE);
                    }else {
                        subRecyView.setVisibility(View.GONE);
                        expand_img1.setVisibility(View.GONE);
                        expand_img.setVisibility(View.VISIBLE);
                    }

                }else  if (helper.getLayoutPosition()==2) {
                    if (subRecyView.getVisibility()==View.GONE) {
                        subRecyView.setVisibility(View.VISIBLE);
                        expand_img.setVisibility(View.GONE);
                        expand_img1.setVisibility(View.VISIBLE);
                    }else {
                        subRecyView.setVisibility(View.GONE);
                        expand_img1.setVisibility(View.GONE);
                        expand_img.setVisibility(View.VISIBLE);
                    }

                }else {
                    expand_img1.setVisibility(View.GONE);
                    expand_img.setVisibility(View.GONE);
                }
            }
        });

    }
}
